home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / ACORNUSERS / EMULATOR / EMUL6502 / Sources / Squares < prev    next >
Text File  |  1998-08-27  |  3KB  |  103 lines

  1. ;Alain BROBECKER (aka baah/Arm's Tech), 23aug1998
  2. ;
  3. ;This program was written to test the good functioning of a 6502 emulator.
  4. ;It works just fine with 'emul6502' and i tried to have as many opcodes or
  5. ;adressing modes as possible, so no optimisations out there.
  6. ;What it does is...
  7. ;  -- Computes squares of [0..127] with 2 methods and store them in memory.
  8. ;     Of course the results are normally the same.
  9. ;  -- Use 2 methods to compare the results. If first method find difference
  10. ;     it jumps at adress 0 (should contain  &00=opcode for 'brk'), and if
  11. ;     second method find differences it jumps at adress 1. If no problem
  12. ;     occured (or your emulator is unable to do the comparisons =) it shall
  13. ;     end with the 'brk' inside the code.
  14.  
  15.             #name       SquaresX
  16.             #list
  17.             #base       &100-4      ;Start assembly here
  18.             #rw         &100        ;Load adress
  19.             #rw         &100        ;Exec adress
  20.  
  21. ;Zero page adresses used as storage
  22. #set        mul1 = &10
  23. #set        mul2 = &11
  24. #set        sqr1 = &10
  25. #set        sqr2 = &12
  26.  
  27. ;compute squares with succesive iterations... (n+1)²=n²+2n+1
  28.   ldx #0                ;counter=2n
  29. .sqr1_one
  30.   txa:clc:adc #1        ;a=2*n+1, and C=0, since 0<n<127
  31.   adc squares,x         ;current+=2n+1
  32.   sta squares+2,x
  33.   lda squares+1,x
  34.   adc #0
  35.   sta squares+3,x
  36.   inx:inx               ;x+=2
  37.  cpx #254:bne sqr1_one
  38.  
  39. ;compute squares with brutal shift multiplication...
  40.   ldy #0                ;counter=n
  41. .sqr2_one
  42.   lda #0                ;initialise result and high(mul2)
  43.   sta z,mul2+1
  44.   sta squares+256,y
  45.   sta squares+257,y
  46.   tya:lsr               ;a=n
  47.   sta z,mul1            ;save n into multiplicands
  48.   sta z,mul2
  49. .sqr2_shift_one
  50.   lsr z,mul1            ;put lower bit in carry
  51.   bcc sqr2_next_shift   ;no addition when carry=0
  52.   clc
  53.   lda z,mul2            ;16 bits addition
  54.   adc squares+256,y
  55.   sta squares+256,y
  56.   lda z,mul2+1
  57.   adc squares+257,y
  58.   sta squares+257,y
  59. .sqr2_next_shift
  60.   asl z,mul2            ;rotate rw in mul2
  61.   rol z,mul2+1
  62.   lda z,mul1
  63.  bne sqr2_shift_one     ;quit when z,mul1=0
  64.   iny:iny               ;y+=2
  65.  bne sqr2_one
  66.  
  67. ;first comparison method, quite stupid
  68.   ldx #0
  69. .cmp1_one
  70.   dex
  71.   beq cmp1_ok
  72.   lda squares,x
  73.   cmp squares+256,x
  74.   beq cmp1_one
  75.   jmp 0
  76. .cmp1_ok
  77.  
  78. ;second method, uses post-indexed indirect adressing and sbc
  79.   lda #squares AND &ff  ;save adresses in zeropage
  80.   sta z,sqr1
  81.   lda #squares>>8
  82.   sta z,sqr1+1
  83.   ldx #(squares+256)AND &ff
  84.   stx z,sqr2
  85.   ldy #(squares+256)>>8
  86.   sty z,sqr2+1
  87.   ldy #0
  88. .cmp2_one
  89.   dey
  90.   beq cmp2_ok
  91.   lda (sqr1),y          ;a=byte pointed by adress at sqr1
  92.   sec
  93.   sbc (sqr2),y
  94.   beq cmp2_one
  95.   jmp 1
  96. .cmp2_ok
  97.   brk
  98.  
  99. .temp
  100.   #rw       0
  101. .squares
  102.   #rw       0
  103.